# _*_ coding : utf-8 _*_
# @Time : 2025/3/28 21:27
# @Author : 梁满仓
# @File : akshare_test
# @Project : stock_of_donnie_day_day_up
import akshare as ak
import pandas as pd

def test_akshare():
    print("="*50)
    print(">>> AKShare 基础测试 <<<")
    print("="*50 + "\n")

    # 1. 测试股票实时行情
    try:
        stock_spot = ak.stock_zh_a_spot()
        print("[股票实时行情] 测试成功！")
        print(f"获取到 {len(stock_spot)} 条股票数据，示例如下：")
        print(stock_spot[["代码", "名称", "最新价", "涨跌幅"]].head(3), "\n")
    except Exception as e:
        print("[股票实时行情] 测试失败:", e)

    # 2. 测试股票历史数据 (贵州茅台)
    try:
        stock_hist = ak.stock_zh_a_daily(symbol="sh600519", adjust="hfq")
        print("[股票历史数据] 测试成功！")
        print("贵州茅台 (600519) 最近5天收盘价：")
        print(stock_hist["close"].tail(), "\n")
    except Exception as e:
        print("[股票历史数据] 测试失败:", e)

    # 3. 测试基金列表
    try:
        fund_list = ak.fund_em_fund_name()
        print("[公募基金列表] 测试成功！")
        print(f"获取到 {len(fund_list)} 只基金，示例如下：")
        print(fund_list[["基金代码", "基金简称"]].head(3), "\n")
    except Exception as e:
        print("[公募基金列表] 测试失败:", e)

    # 4. 测试宏观经济数据 (中国GDP)
    try:
        gdp_data = ak.macro_china_gdp()
        print("[中国GDP数据] 测试成功！")
        print("中国年度GDP数据（单位：亿元）：")
        print(gdp_data.tail(), "\n")
    except Exception as e:
        print("[中国GDP数据] 测试失败:", e)

    print("="*50)
    print("测试完成！请检查上方输出是否正常。")

if __name__ == "__main__":
    test_akshare()
